import {
    createSlice,
    createAsyncThunk
} from '@reduxjs/toolkit'

import {movieRequest} from '../../api'

//异步请求写外面
    export const getMovieAction = createAsyncThunk('movie/getMovieList',async()=>{
        const re = await movieRequest()
        console.log(re);
        return re.data.data.list
    })


const movieSlice = createSlice({
    name:'movie',
    initialState:{
        movieList:[]
    },
    reducers:{

    },

    extraReducers:{
    [getMovieAction.fulfilled](prev,action){
        console.log("异步action成功--getMovieAction");
        prev.movieList = action.payload
    },
    [getMovieAction.rejected](prev,action){
        console.log("异步action失败--getMovieAction");
    },
    [getMovieAction.pending](prev,action){
        console.log("异步action正在进行中--getMovieAction");
    },
    }
})

export default movieSlice.reducer



